#include<stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    int x[6];
    for (int i = 0; i < 6; i++)
    {
        scanf("%d",&x[i]);
    }
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        printf("%d %d",a,b);
        switch (a)
        {
        case 1:
            switch (b)
            {
            case 1:
                break;
            case 2:
                printf("%d\n",x[2]);
                break;
            case 3:
                printf("%d\n",x[4]);
                break;
            case 4:
                printf("%d\n",x[1]);
                break;
            case 5:
                printf("%d\n",x[3]);
                break;
            case 6:
                break;
            default:
                break;
            }
            break;
        case 2:
            switch (b)
            {
            case 1:
                printf("%d\n",x[3]);
                break;
            case 2:
                break;
            case 3:
                printf("%d\n",x[0]);
                break;
            case 4:
                printf("%d\n",x[5]);
                break;
            case 5:
                break;
            case 6:
                printf("%d\n",x[2]);
                break;
            default:
                break;
            }
            break;
        case 3:
            switch (b)
            {
            case 1:
                printf("%d\n",x[1]);
                break;
            case 2:
                printf("%d\n",x[5]);
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                printf("%d\n",x[0]);
                break;
            case 6:
                printf("%d\n",x[4]);
                break;
            default:
                break;
            }
            break;
        case 4:
            switch (b)
            {
            case 1:
                printf("%d\n",x[4]);
                break;
            case 2:
                printf("%d\n",x[0]);
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                printf("%d\n",x[5]);
                break;
            case 6:
                printf("%d\n",x[1]);
                break;
            default:
                break;
            }
            break;
        case 5:
            switch (b)
            {
            case 1:
                printf("%d\n",x[2]);
                break;
            case 2:
                break;
            case 3:
                printf("%d\n",x[5]);
                break;
            case 4:
                printf("%d\n",x[0]);
                break;
            case 5:
                break;
            case 6:
                printf("%d\n",x[3]);
                break;
            default:
                break;
            }
            break;
        case 6:
            switch (b)
            {
            case 1:
                break;
            case 2:
                printf("%d\n",x[3]);
                break;
            case 3:
                printf("%d\n",x[1]);
                break;
            case 4:
                printf("%d\n",x[4]);
                break;
            case 5:
                printf("%d\n",x[2]);
                break;
            case 6:
                break;
            default:
                break;
            }
            break;
        default:
            break;
        }
    }
}